package Box2D.Common
{
	public class b2Wrapper implements Ib2Wrapper
	{
		protected var _wrapper:Object;
		public function b2Wrapper(wrapper:Object=null)
		{
			_wrapper = wrapper
		}		
		protected function get struct():Ib2Struct{return b2Base.impl.struct}
		public function get wrapper():Object{return _wrapper}
		public function set wrapper(value:Object):void{_wrapper=value}
		/***
		 * 不内嵌wrapper指针的调用
		 */
		protected function callDirect(funcName:String,...args):*{
			return b2Base.impl.lib[funcName].apply(null,args);
		}
		/***
		 * 内嵌wrapper指针的调用
		 */
		protected function call(funcName:String,...args):*{
			if(_wrapper==null)
				throw new Error('wrapper空');
			args.unshift(_wrapper);
			args.unshift(funcName);
			return callDirect.apply(null,args);
		}
		
		protected function getNumber(position:int):Number{return b2Base.impl.mem._mrf(_wrapper+position)}
		protected function setNumber(position:int,value:Number):void{
			if(isNaN(value))
				throw 'number value NaN';
			b2Base.impl.mem._mwf(_wrapper+position,value)
		}
		
		protected function getInt(position:int):int{return b2Base.impl.mem._mr32(_wrapper+position)}
		protected function setInt(position:int,value:int):void{b2Base.impl.mem._mw32(_wrapper+position,value)}
		
		protected function getInt8(position:int):int{return b2Base.impl.mem._mru8(_wrapper+position)}
		protected function setInt8(position:int,value:int):void{b2Base.impl.mem._mw8(_wrapper+position,value)}
		
		protected function getInt16(position:int):int{return b2Base.impl.mem._mrs16(_wrapper+position)}
		protected function setInt16(position:int,value:int):void{b2Base.impl.mem._mw16(_wrapper+position,value)}
		
		protected function getUInt16(position:int):uint{return b2Base.impl.mem._mru16(_wrapper+position)}
		protected function setUInt16(position:int,value:uint):void{b2Base.impl.mem._mw16(_wrapper+position,value)}
		
		protected function getUInt8(position:int):uint{return b2Base.impl.mem._mru8(_wrapper+position)}
		protected function setUInt8(position:int,value:uint):void{b2Base.impl.mem._mw8(_wrapper+position,value)}
		
		protected function getBoolean(position:int):Boolean{return b2Base.impl.mem._mru8(_wrapper+position)==1}
		protected function setBoolean(position:int,value:Boolean):void{b2Base.impl.mem._mw8(_wrapper+position,value?1:0)}
		
		protected function getPoint(position:int):*{return b2Base.impl.mem._mr32(_wrapper+position)}
		protected function setPoint(position:int,value:*):void{b2Base.impl.mem._mw32(_wrapper+position,value)}
	}
}